﻿using Microsoft.AspNetCore.Mvc;
using ZGL.Api.Models.dto;
using ZGL.Api.Services.Menu;
using ZGL.Api.Services.User;
using ZGL.Api.Utils;

namespace ZGL.Api.Controllers
{
    /// <summary>
    /// 菜单管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        public readonly IMenuService MenuService;
        public MenuController(IMenuService MenuService)
        {
            this.MenuService = MenuService;
        }

        /// <summary>
        /// 菜单列表
        /// </summary>
        [HttpPost]
        public IActionResult GetMenuList(MenuDto menuDto)
        {
            Dictionary<string, object> MenuList = MenuService.getMenuList(menuDto);

            return new ObjectResult(new R(data: MenuList));
        }

        #region 菜单新增
        /// <summary>
        /// 菜单新增
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult addMenu(MenuAddDto menu)
        {
            MenuService.addMenu(menu);
            return new ObjectResult(new R(data: null));
        }
        #endregion
        #region 修改菜单
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult putMenu(MenuPutDto menu)
        {
            MenuService.putMenu(menu);
            return new ObjectResult(new R(data: null));
        }
        #endregion
        /// <summary>
        /// 获取菜单详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult getMenu(long id)
        {
            var menu = MenuService.getMenu(id);
            return new ObjectResult(new R(data: menu));
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        #region 删除菜单
        [HttpDelete]
        public IActionResult delMenu(long id)
        {
            MenuService.delMenu(id);
            return new ObjectResult(new R(data: null, code: 200, message: "请求成功"));
        }
        #endregion

    }
}
